package m202406.d23;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/23 21:31
 */
public class Q28 {
    public static void main(String[] args) {
        Q28 q28 = new Q28();
        q28.strStr("sadbutsad", "sad");
    }

    public int strStr(String haystack, String needle) {
        for (int i = 0; i < haystack.length(); i++) {
            if (haystack.charAt(i) != needle.charAt(0)) {
                continue;
            }
            int j = 1;
            for (; j < needle.length() && i + j < haystack.length(); j++) {
                if (haystack.charAt(i + j) != needle.charAt(j)) {
                    break;
                }
            }
            if (j == needle.length()) {
                return i;
            }
        }
        return -1;
    }
}
